package com.ruoyi.common.qy.utils;

public class ByteToMBConverter {

    public static double bytesToMB(long bytes) {
        return bytes / (1024.0 * 1024.0);
    }

    public static double bytesToMB(int bytes) {
        return bytes / (1024.0 * 1024.0);
    }

    public static void main(String[] args) {
        // 示例1：基本转换
        long fileSizeInBytes = 10485760L; // 10 MB
        double sizeInMB = bytesToMB(fileSizeInBytes);
        System.out.println(fileSizeInBytes + " 字节 = " + sizeInMB + " MB");

        // 示例2：获取文件大小并转换
        java.io.File file = new java.io.File("test.txt");
        if (file.exists()) {
            long fileSize = file.length();
            double mbSize = bytesToMB(fileSize);
            System.out.println("文件大小: " + mbSize + " MB");
        }

        // 示例3：格式化输出（保留2位小数）
        System.out.printf("格式化输出: %.2f MB\n", sizeInMB);
    }
}
